package org.elephas.webapp.frontend.page.blog;

import org.apache.wicket.Component;
import org.apache.wicket.PageParameters;
import org.apache.wicket.RestartResponseException;
import org.elephas.model.Post;
import org.elephas.webapp.frontend.component.PostPanel;
import org.elephas.webapp.model.DetachablePostModel;

/**
 * Page for a post.
 * 
 * @author Gerolf Seitz
 * 
 */
public class BlogPostPage extends BlogBasePage {

	private static final long serialVersionUID = 1L;

	public BlogPostPage(PageParameters params) {
		super(params);

	}

	@Override
	protected void checkParameters(PageParameters params) {
		super.checkParameters(params);
		if (params.size() == 1) {
			// assume that the first parameter is the blog name. redirect to the
			// blog front page.
			setRedirect(true);
			throw new RestartResponseException(BlogFrontPage.class, params);
		}
	}

	@Override
	protected Component newContent(String id) {
        return getTheme().newPostPageContent(id, getBlog(), this);
	}

	/**
	 * Creates a {@link PageParameters} object based on the given {@link Post}
	 * object.
	 * 
	 * @param post
	 *            the post
	 * @return the page parameter for the {@link BlogPostPage}
	 */
	public static PageParameters constructPageParameters(Post post) {
		PageParameters params = new PageParameters();
		if (post != null) {
			params.add(BlogFrontPage.BLOG_NAME, post.getBlog().getName());
			params.add(BlogFrontPage.POST_UUID, post.getUuid());
		}
		return params;
	}
}
